package com.hy.study.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hy.study.dao.UserMapper;
import com.hy.study.dto.User;
import com.hy.study.service.UserService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author huyong
 * @date 2024 年 01 月 05 日 15:49: 47
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    /**
     * 使用了一个缓存名叫 USER
     *
     * @param userId
     *
     * @return
     */
   // @Cacheable(value = "USER", key = "#userId") redis 的缓存
    @Cacheable(value = "USER",key = "#userId")  //eh缓存
    @Override
    public User getUserInfoByUserId(Integer userId) {
        return this.getById(userId);
    }

    /**
     * 清空缓存
     *
     * @param user
     */
    //@CacheEvict(value = "USER", key = "#user.id") //redis cache
    @CacheEvict(value = "USER", key = "#user.id") //eh cache
    public void updateUser(User user) {
        this.saveOrUpdate(user);
    }

    /**
     * 清空缓存
     */
   // @CacheEvict(value = "USER", allEntries = true, beforeInvocation = true) //redis cache
    @CacheEvict(value = "USER", allEntries = true, beforeInvocation = true) // eh cache
    public void reload() {

    }
}
